package Server.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * Entity - 消息
 *
 *
 * @version 0.1
 *
 */
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicInsert
@DynamicUpdate
public class Message implements Serializable,Cloneable{
    @Id
    @GeneratedValue(generator = "NumberIdProduce")
    @GenericGenerator(name="NumberIdProduce", strategy="Server.tool.NumberIdProduce")
    private String uuid;

    @Lob
    @Column
    private String message;

    //发送人
    @ManyToOne
    @JoinColumn(name = "authorId")
    private Users author;

    /*
    *
    *接收人
    * */
    @ManyToOne
    @JoinColumn(name = "userId")
    private Users user;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @LastModifiedDate
    @Column
    private Date modifiedTime;
    /*
    * 0：未读
    * 1：已读
    * */
    @Column
    private Integer readMI;


    @ManyToOne
    @JoinColumn(name = "shopOrderId")
    private  ShopOrder shopOrder;

    @ManyToOne
    @JoinColumn(name = "shopSpecId")
    private  ShopSpec shopSpec;

    private static Message erpProduct = new Message();

    public Message(){
        super();
    }

    public static Message getInstance(){
        try {
            return (Message) erpProduct.clone();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Message();
    }

    public ShopSpec getShopSpec() {
        return shopSpec;
    }

    public void setShopSpec(ShopSpec shopSpec) {
        this.shopSpec = shopSpec;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Users getAuthor() {
        return author;
    }

    public void setAuthor(Users author) {
        this.author = author;
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }

    public Date getModifiedTime() {
        return modifiedTime;
    }

    public void setModifiedTime(Date modifiedTime) {
        this.modifiedTime = modifiedTime;
    }

    public Integer getReadMI() {
        return readMI;
    }

    public void setReadMI(Integer readMI) {
        this.readMI = readMI;
    }

    public ShopOrder getShopOrder() {
        return shopOrder;
    }

    public void setShopOrder(ShopOrder shopOrder) {
        this.shopOrder = shopOrder;
    }
}
